@charset "UTF-8";

// 选择文本样式
@mixin selection($bgColor:#e74c3c, $color:#173c46) {
  ::selection {
    background-color: $bgColor;
    color: $color;
  }

  ::-moz-selection {
    background-color: $bgColor;
    color: $color;
  }

  ::-webkit-selection {
    background-color: $bgColor;
    color: $color;
  }
}

// 表单禁用样式
@mixin disabled($bgColor: #e6e6e6, $textColor:#ababab) {
  background-color: $bgColor !important;
  color: $textColor !important;
  cursor: not-allowed !important;
  // pointer-events: none !important;
}

// 设置过渡效果
@mixin transtion($transition-property:all) {
  transition: $transition-property .3s ease-in-out;
}




// 文本截取(单行、多行,截取宽度)
@mixin ellipsis($line: 1, $substract: 0) {
  @if $line==1 {
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  @else {
    display: -webkit-box;
    -webkit-line-clamp: $line;
    -webkit-box-orient: vertical;
  }

  width: 100% - $substract;
  overflow: hidden;
}



// 图片保持宽高比
@mixin aspectRatio($width:16, $height:9) {

  // 默认16:9
  @at-root #{&}::before {
    content: "";
    float: left; // 元素需要浮动，不然后面元素需要使用绝对定位
    height: 0; // 本身高度必须置0
    padding-top: percentage($height/$width); // 使用padding-top撑起高度
  }

  @at-root #{&}::after {
    // 清除浮动
    content: "";
    display: table;
    clear: both;
  }
}


@mixin clearfix {
  &:after {
    content: "";
    display: table;
    clear: both;
  }
}

@mixin scrollBar {
  &::-webkit-scrollbar-track-piece {
    background: #d3dce6;
  }

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: #99a9bf;
    border-radius: 20px;
  }
}

// absolute 定位
// @include abs-pos(10px, 10px, 5px, 15px);
@mixin abs-pos ($top: auto, $right: auto, $bottom: auto, $left: auto) {
  position: absolute;
  top: $top;
  right: $right;
  bottom: $bottom;
  left: $left;
}

/// Make a context based selector a little more friendly
/// @author Hugo Giraudel
/// @param {String} $context
/* 
  例：
  .foo {
    @include when-with('.active') {
      animation: fadeIn 0.3s 1s forwards;
    }
  }
  相当于
  .active .foo {
    animation: fadeIn 0.3s 1s forwards;
  }
*/
@mixin when-with($context) {
  #{$context} & {
    @content;
  }
}

@mixin active-ok($color1, $color2) {
  position: relative;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid $color1;

  &.active {
    border-color: $color2;

    &::before {
      content: "";
      display: block;
      position: absolute;
      right: 0;
      bottom: 0;
      width: 0;
      height: 0;
      border-width: 18px 15px;
      border-style: solid;
      border-color: transparent $color2 $color2 transparent;
    }

    &::after {
      content: "";
      display: block;
      position: absolute;
      transform: rotate(36deg);
      right: 5px;
      bottom: 5px;
      width: 9px;
      height: 14px;
      border-width: 2px;
      border-style: solid;
      border-color: transparent #fff #fff transparent;
    }
  }
}


/* media媒体查询 */
/* 
  用法
  .foo {
    @include respond-to('sm') {
      padding-left: 20px;
      padding-right: 20px;
    }
  }
  产出
  @media only screen and (min-width: 480px) {
    .foo {
      padding-left: 20px;
      padding-right: 20px;
    }
  }
*/
$breakpoints: ('sm': 'only screen and  (min-width: 480px)',
  'md': 'only screen and ( min-width: 768px)',
  'lg': 'only screen and ( min-width: 992px)'
) !default;

@mixin respond-to($breakpoint) {
  $query: map-get($breakpoints, $breakpoint);

  @if not $query {
    @error 'No value found for `#{$breakpoint}`. Please make sure it is defined in `$breakpoints` map.';
  }

  @media #{if(type-of($query) == 'string', unquote($query), inspect($query))} {
    @content;
  }
}

/* 
  文字长阴影 
  使用
    h1 {
      @include longshadow(darken($color, 5%));
    }
*/

@function makelongshadow($color) {
  $val: 0px 0px $color;

  @for $i from 1 through 200 {
    $val: #{$val},
    #{$i}px #{$i}px #{$color};
  }

  @return $val;
}

@mixin longshadow($color) {
  text-shadow: makelongshadow($color);
}

// 为颜色添加白色，以百分比形式
@function tint($color, $percent) {
  @return mix(white, $color, $percent);
}

// 为颜色添加黑色，以百分比形式
@function shade($color, $percent) {
  @return mix(black, $color, $percent);
}

// 
@mixin shrink($n:0) {
  flex-shrink: $n;
  min-width: 0;
  min-height: 0;
}

// 
@mixin grow($n:1) {
  flex-grow: $n;
  min-width: 0;
  min-height: 0;
}

// 
@mixin flex($just:initial, $align:stretch) {
  display: flex;
  justify-content: $just;
  align-items: $align;
}

// 文本截取(单行、多行,截取宽度)
@mixin ellipsis($line: 1, $substract: 0) {
  @if $line==1 {
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  @else {
    display: -webkit-box;
    -webkit-line-clamp: $line;
    -webkit-box-orient: vertical;
  }

  width: 100% - $substract;
  overflow: hidden;
}

// 设置移动端不同dpr屏幕下的字体大小
@mixin fontSize($font-size) {
  font-size: $font-size * 1px;

  [data-dpr="1"] & {
    font-size: $font-size * .5px;
  }

  [data-dpr="2"] & {
    font-size: $font-size * 1px;
  }

  [data-dpr="3"] & {
    font-size: $font-size * 1.5px;
  }
}



/* 
  $grid: inline-grid / grid
*/
@mixin grid($grid:grid, $columns:1, $rows:1) {
  display: $grid;
  grid-template-columns: $columns;
  grid-template-rows: $rows;
}

// 设置html基本字体样式
@mixin htmlFont($pageType:PC) {
  // 设置字体平滑
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  @if (unquote($pageType)==PC) {
    font-size: 16px;
    line-height: 1.625;
    font-family: $baseFontPC;
  }

  @else {
    font-size: ($designWidth/10)/($designWidth/2)*100vw; // 设计图750，默认1rem为7.5，所以通过这种方式将html的font-size设置为75px，配套的px2rem中1rem也为75px；如果设置为font-size为7.5，可以做到rem、vw最终得到相同的px值，但是因为有字体大小限制(最小12px)，所以只能使用75px
    line-height: 1.5;
    font-family: $baseFontMobile; // 为了不让基准字体无限变大或变小破坏布局，所以必须做一个限制

    @media screen and (max-width: 320px) {
      // <320时字体统统为64px
      font-size: 64px;
    }

    @media screen and (min-width: 640px) {
      // >640时字体统统为128px
      font-size: 128px;
    }
  }
}


// 因为在移动端html的字体是根据视口变化的，所以body字体大小需要重新设置，让子元素能继承
@mixin bodyFontSize($pageType:M) {
  @if (unquote($pageType)==M) {
    font-size: 16px;

    @media screen and (min-width: 375px) {
      // iPhone6的375px尺寸作为16px基准，414px正好18px大小, 600 20px
      font-size: calc(100% + 2 * (100vw - 375px) / 39);
      font-size: calc(14px + 2 * (100vw - 375px) / 39);
    }

    @media screen and (min-width: 414px) {
      /// 414px-1000px每100像素宽字体增加1px(18px-22px)
      font-size: calc(112.5% + 4 * (100vw - 414px) / 586);
      font-size: calc(18px + 4 * (100vw - 414px) / 586);
    }

    @media screen and (min-width: 600px) {
      // 600px-1000px每100像素宽字体增加1px(20px-24px)
      font-size: calc(125% + 4 * (100vw - 600px) / 400);
      font-size: calc(20px + 4 * (100vw - 600px) / 400);
    }

    @media screen and (min-width: 1000px) {
      // 1000px往后是每100像素0.5px增加
      font-size: calc(137.5% + 6 * (100vw - 1000px) / 1000);
      font-size: calc(22px + 6 * (100vw - 1000px) / 1000);
    }

    // body 也增加最大最小宽度限制，避免默认100%宽度的 block 元素跟随 body 而过大过小，并让其居中
    max-width: 640px;
    min-width: 320px;
    margin-left: auto;
    margin-right: auto;
  }
}


@mixin mg($px) {
  margin: $px;
  &-lr {
    margin:0 $px;
  }
  &-tb {
    margin:$px 0;
  }
  &-l {
    margin-left:$px;
  }
  &-r {
    margin-right:$px;
  }
  &-t {
    margin-top:$px;
  }
  &-b {
    margin-bottom:$px;
  }
}

@mixin pd($px) {
  padding: $px;
  &-lr {
    padding:0 $px;
  }
  &-tb {
    padding:$px 0;
  }
  &-l {
    padding-left:$px;
  }
  &-r {
    padding-right:$px;
  }
  &-t {
    padding-top:$px;
  }
  &-b {
    padding-bottom:$px;
  }
}